﻿// This code is released under the BSD license.
namespace PugLib.UI.Controls
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public partial class PugDialogButton : UserControl, IPugDialogResult
    {
        private string _description;
        private string _label;

        public PugDialogButton()
        {
            InitializeComponent();
        }

        public Image Image
        {
            get { return btnPugDialogButton.Values.Image; }
            set { btnPugDialogButton.Values.Image = value; }
        }

        public string TextPrimary
        {
            get { return _label; }
            set
            {
                _label = value;
                UpdateButtonText();
            }
        }

        public string TextSecondary
        {
            get { return _description; }
            set
            {
                _description = value;
                UpdateButtonText();
            }
        }

        #region IPugDialogResult Members

        public PugDialogResult Result { get; set; }

        #endregion

        private void UpdateButtonText()
        {
            btnPugDialogButton.Text = _label;
            btnPugDialogButton.Values.ExtraText = _description;
        }


        private void btnPugDialogButton_Click(object sender, EventArgs e)
        {
            Form parentForm = FindForm();
            if (parentForm == null)
            {
                return;
            }

            IPugDialogResult parent = parentForm as IPugDialogResult;
            if (parent == null)
            {
                return;
            }

            parent.Result = Result;
            parentForm.Close();
        }
    }
}